﻿
/*----------------------------------------------------------------
 * 创建时间：2023/7/21 19:39:16
 * 作  者：wenlli 
 * 项  目：Minotaur.App.Core.Mvvm 
 * 描  述：初始化模块
 *
 * ----------------------------------------------------------------
 * 修改人：
 * 时  间：
 * 修改说明：
 * 
 *----------------------------------------------------------------*/


using Minotaur.App.Modules.FlowProcess;
using Minotaur.App.Modules.Home;
using Minotaur.App.Modules.OrganizationSet;
using Minotaur.App.Modules.PersonelSet;
using Minotaur.App.Modules.SystemSet;
using Prism.Ioc;
using Prism.Modularity;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Minotaur.App.ViewModels
{
    /// <summary>
    /// 初始化模块
    /// </summary>
    public class ModuleCatalogManager
    {
        private readonly IModuleCatalog catalog;
        private readonly IContainerProvider containerProvider;
        public ModuleCatalogManager(IModuleCatalog catalog, IContainerProvider containerProvider)
        {
            this.catalog = catalog;
            this.containerProvider = containerProvider;
        }

        /// <summary>
        /// 初始化模块
        /// </summary>
        public void InitModules()
        {
            this.catalog.AddModule<HomeModule>("home");
            this.catalog.AddModule<SystemSetModule>("system");
            this.catalog.AddModule<PersonelSetModule>("personnel");
            this.catalog.AddModule<SystemSetModule>("document");
            this.catalog.AddModule<OrganizationSetModule>("organization");
            this.catalog.AddModule<FlowProcessModule>("flowprocess");
            this.OpendModule("home");
        }

        public bool OpendModule(string moduleCode)
        {
            bool result = true;
            IModuleManager moduleManager = containerProvider.Resolve<IModuleManager>();
            if (moduleManager.ModuleExists(moduleCode))
            {
                moduleManager.LoadModule(moduleCode);
            }
            else
            {
                result = false;
            }
            return result;
        }
    }
}
